import http.client

# 首页
conn = http.client.HTTPConnection('localhost')
conn.request('GET', '/smeoa/index.php?m=login&a=index')
setCookie = conn.getresponse().getheader('Set-Cookie')
# print(setCookie)
sessionID = setCookie.split(';')[0]
# print(sessionID)

# 登陆
conn = http.client.HTTPConnection('localhost')
param = 'emp_no=admin&password=admin'
header = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
          'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': sessionID}
conn.request('POST', '/smeoa/index.php?m=login&a=check_login', body=param, headers=header)
content = conn.getresponse().read().decode()
print(content)
# if not content:
#     print('登陆成功')
# else:
#     print('登陆失败')

if content == '':
    print('登陆成功')
else:
    print('登陆失败')

# 新增公告
conn = http.client.HTTPConnection('localhost')
param = 'id=&opmode=add&admin=&write=&read=&folder_list=0&name=test1127-2&folder_name=test2&pid=70&sort=&is_del=0&remark='
header = {'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': sessionID}
conn.request('POST', '/smeoa/index.php?m=notice_folder&a=save', body=param, headers=header)
content = conn.getresponse().read()
# print(content.decode())


#   新增日报
conn = http.client.HTTPConnection('localhost')
param = '''
-----------------------------7e214014160492
Content-Disposition: form-data; name="ajax"

0
-----------------------------7e214014160492
Content-Disposition: form-data; name="add_file"


-----------------------------7e214014160492
Content-Disposition: form-data; name="executor"

员工5007|56;
-----------------------------7e214014160492
Content-Disposition: form-data; name="opmode"

add
-----------------------------7e214014160492
Content-Disposition: form-data; name="name"

title0307
-----------------------------7e214014160492
Content-Disposition: form-data; name="expected_time"

2018-03-15 11:40
-----------------------------7e214014160492
Content-Disposition: form-data; name="content"

content
-----------------------------7e214014160492--
'''
headers = {'Content-Type': 'multipart/form-data; boundary=---------------------------7e214014160492',
           'Cookie': sessionID}
conn.request('POST', '/smeoa/index.php?m=task&a=save', body=param.encode(), headers=headers)
response = conn.getresponse().read().decode()
print(response)
